feat: keep compatible with unexpected policy, revert PR: https://github.com/casbin/Casbin.NET/pull/337 #350
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixed: #335
This change will be compatible with some unforeseen policy in which values count less or longer than model tokens.
For example, If your policy definition is:
When we attempt to add the following policy, the old logic will ignore this action and return false.
Furthermore, because the logic for checking unexpected policies is executed after the Adapter is called, the database will contain this anomalous data, and it will never be able to be loaded into memory.
Starting from this change, the unexpected policies will be trimmed into the following expected format and can be smoothly added to the policy store. Of course, the return value will be true. Here is a simple test:
This is a more gentle approach. Conversely, there is another option where we throw an exception for all unexpected policies.
But I believe this could be a change with high risk to the user. If the user prefers a more stringent method, we can provide an option for them to choose at later versions.
QA:
Do similar issues exist in other languages?
The Golang version will exist, but its behavior will be somewhat different. It allow to add the unexpected policies to memory store, but will return an error when loading policy.
https://github.com/casbin/casbin/blob/64efe3d122bfe68c9cf68e1bd174173a61f11743/model/policy.go#L155-L176
Why revert feat: fix null value handling logic #337
Of course, it is also a method to address this issue, but its implementation logic is not very sound. It abandons the optimization of genericization and is unable to handle situations where the number of incoming values exceeds the number of tokens.